package svg

import (
	"io"
	"mime"

	"gosvg/dom"
)

const (
	SvgNamespace   = `http://www.w3.org/2000/svg`
	XlinkNamespace = `http://www.w3.org/1999/xlink`
)

func init() {
	mime.AddExtensionType(".svg", "image/svg+xml")
}

type SvgDocument struct {
	*dom.Element
}

func SVG() *SvgDocument {
	ele := dom.MakeElementNs("svg", SvgNamespace)
	ele.AddToAttribute("xmlns", "http://www.w3.org/2000/svg")
	ele.AddToAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink")
	return &SvgDocument{Element: ele}
}

func (svg *SvgDocument) ViewBox(top, left, width, height float64) *SvgDocument {
	svg.SetNamespacedAttribute("viewBox", SvgNamespace,
		fVal(top)+
			" "+
			fVal(left)+
			" "+
			fVal(width)+
			" "+
			fVal(height))
	return svg
}



func (svg *SvgDocument) Write(writer io.Writer) {
	w := dom.NewWriter(writer, /*debug:*/ false, make(map[string]string))
	svg.XmlWrite(w)
}
